package com.hello.system.api.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import com.hello.common.core.domain.R;
import com.hello.system.api.RemoteWxService;

import java.util.HashMap;
import java.util.Map;

/**
 * 微信用户服务降级处理
 * 
 * @author hello
 */
@Component
public class RemoteWxFallbackFactory implements FallbackFactory<RemoteWxService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteWxFallbackFactory.class);

    @Override
    public RemoteWxService create(Throwable throwable) {
        log.error("微信用户服务调用失败:{}", throwable.getMessage());
        return new RemoteWxService() {
            @Override
            public R<Map<String, Object>> getWxOpenid(Map<String, String> params, String source) {
                log.error("获取微信openid失败:{}", throwable.getMessage());
                Map<String, Object> errorMap = new HashMap<>();
                errorMap.put("error", "获取微信openid失败: " + throwable.getMessage());
                return R.fail("获取微信openid失败: " + throwable.getMessage());
            }
        };
    }
} 